package com.example.exercise.minio.controller;

import com.example.exercise.minio.service.MinIoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class MinIoDemoController {
    @Autowired
    private MinIoService minIoService;

    @GetMapping("/upload")
    public Object upload(MultipartFile file) {
        String bucketName = "haha";
        if(!minIoService.bucketExists(bucketName)) {
            return "没有桶";
        }
        String upload = minIoService.upload(file, bucketName);
        return bucketName+"/"+upload;
    }

    @GetMapping("/createBucket")
    public Object createBucket() {
        String bucketName = "haha";
        if(minIoService.bucketExists(bucketName)) {
            return "桶已存在，不需要创建";
        }
        if(minIoService.makeBucket(bucketName)) {
            return "创建桶成功";
        }
        return "null";
    }
}
